<template>
  <div class="tab" @click="tabChange">
    
    
    <div style="width: 100%; overflow-x:auto; overflow-y:hidden; white-space:nowrap;">
      <div v-for="(item,index) in data.tabName" :key="index" class="wrap">
        <span :class="data.activeIndex===index?'common active':'common default'" :data-index="index">{{ data.tabName[index] }}</span>
      </div>
    </div>
    

    <span class="top">置顶</span>
    <div class="list" v-for="(item, index) in data.list" :key="index">
      <p class="title">
        <span class="prev">{{item.title}}</span>
        <Livedynamic class="jumper" />
      </p>
      <p class="info">
        <span v-if="false">
          <span>作者：快医生</span>
          <span class="gap">2021年6月19日</span>
        </span>
        <span v-if="false">
          <span>作者：快医生</span>
          <span class="gap">2021年6月19日</span>
          <img src="../../../assets/img/eye.png" class="eye gap">
          <span>2068</span>
        </span>
        <span v-if="true">
          <span>嘉宾：郑州大学第一附属医院-梗迪</span>
          <span class="gap">首次分享时间：2021-04-22</span>
        </span>
      </p>
    </div>
  </div>
</template>

<script>

import {reactive} from 'vue'
// 引入直播动态图标组件
import Livedynamic from './Livedynamic'


export default {
  name: 'Tabbar',
  components:{
    Livedynamic
  },
  setup(props, context){
    // tabChange 方法
    const tabChange = (e)=>{ 
      if(e && e.target.getAttribute('data-index') !== null){
        data.activeIndex = Number(e.target.getAttribute('data-index'))
        console.log(data.activeIndex)
      }
    }
    //  定义数据
    const data = reactive({ // 数据
      activeIndex: 0,
      tabName:['推荐', '学术会议', '空中课堂', '在线公开课', '热门资讯', '医学专栏', '医学专栏'],
      list:[
        { 
          title:'为什么脑梗塞病人更容易复发？原因究竟是什么？', 
          info:'作者：快医生 2021年6月19日'
        },
        { 
          title:'中国全国肠道大会开幕式第一会场-北京（直播中）', 
          info:'作者：快医生 2021年6月19日'
        },
        { 
          title:'为什么脑梗塞病人更容易复发？原因究竟是什么？', 
          info:'作者：快医生 2021年6月19日'
        }
      ]
    })

    return {
      tabChange,
      data
    }
  } 
  
}
</script>

<style lang="scss" scoped>
.active{
  color: #fff;
  background: #4084F5;
}
.default{
  color: #525252;
  background: #fff;
}
.tab {
  box-sizing: border-box;
  padding: 2.5rem 0 0 2.5rem;
  text-align: left;
  margin: 0 auto;
  width: 37.5rem;
  .wrap{
    display: inline-block;
  }
  .common {
    height: 1.7rem;
    font-size: 1.2rem;
    font-weight: 500;
    margin-right: .3rem;
    padding: 0 .3rem;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .7rem;
  }
  .top{
    display: block;
    width: 2.7rem;
    height: 1.2rem;
    color: #fff;
    font-size: 1rem;
    background: #D50000;
    text-align: center;
    border-radius: .2rem;
    padding: .1rem 0;
    margin-top: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .list{
    width: 32.5rem;
    height: auto;
    border-bottom:  1px solid #eee;
    padding-top: 1rem;
    .title{
      font-size: 1.4rem;
      font-weight: 500;
      color: #000;
      letter-spacing: 0;
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      .jumper{
        margin-top: .3rem;
      }
      .prev{
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .info{
      display: flex;
      flex-direction: row;
      align-items: center;
      font-size: 1rem;
      font-weight: 400;
      color: #999;
      margin: 1rem 0;
      letter-spacing: 0;
      .gap{
        margin-left: .8rem;
      }
      .eye{
        display: inline-block;
        width: 1.6rem;
        height: 1.6rem;
        vertical-align: middle;
      }
    }
  }
}


</style>
